﻿using System.Runtime.InteropServices;

namespace Core.Experiment
{
    [StructLayout(LayoutKind.Explicit)]
    public struct IPAddress
    {
        [FieldOffset(0)]
        public int Address;
        [FieldOffset(0)]
        public byte Byte1;
        [FieldOffset(1)]
        public byte Byte2;
        [FieldOffset(2)]
        public byte Byte3;
        [FieldOffset(3)]
        public byte Byte4;

        public IPAddress(int address) : this()
        {
            Address = address;
        }

        public override string ToString() => $"{Byte1}.{Byte2}.{Byte3}.{Byte4}";
    }
}


//var ip = new IpAddress(new Random().Next());
//Console.WriteLine($"{ip} = {ip.Address}");
//ip.Byte1 = 192;
//ip.Byte2 = 168;
//Console.WriteLine($"{ip} = {ip.Address}");

//输出结果：

//47.29.249.122 = 2063146287
//192.168.249.122 = 2063182016
